from django.db import models
from django.contrib.auth.models import User
from django_extensions.db.fields import UUIDField

class UserProfile(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	user = models.ForeignKey(User, unique=True)
	gamePlay = models.ManyToManyField('Game', related_name='PlayGames')
	gameControl = models.ManyToManyField('Game', related_name='ControlGames')	

class GameState(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	user = models.ForeignKey(User)
	game = models.ForeignKey('Game')
	balance = models.IntegerField(blank=False)
	debt = models.PositiveIntegerField()
	round = models.IntegerField()
	
class Island(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	state = models.ForeignKey('GameState')
	cost = models.IntegerField() # Gaat over geld
	capacity = models.IntegerField() # Grootte van het eiland
	currentContent = models.PositiveIntegerField()
	efficiency = models.IntegerField() # Waarschijnlijk gaan we deze niet gebruiken, o?

class StateMill(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	state = models.ForeignKey('GameState')
	noOfMills = models.PositiveIntegerField()
	typeOfMill = models.ForeignKey('Windmill')
	noOfMaintenance = models.PositiveIntegerField()
	noOfBrokenMills = models.PositiveIntegerField()
	noOfMills1Month = models.PositiveIntegerField()
	noOfMills2Months = models.PositiveIntegerField()
	noOfMills3Months = models.PositiveIntegerField()
	
class DecisionMill(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	decision = models.ForeignKey('Decision')
	noOfMills = models.PositiveIntegerField()
	typeOfMill = models.ForeignKey('Windmill')
	noOfMaintenance = models.PositiveIntegerField()
	noOfBrokenMills = models.PositiveIntegerField()
	noOfMills1Month = models.PositiveIntegerField()
	noOfMills2Months = models.PositiveIntegerField()
	noOfMills3Months = models.PositiveIntegerField()	
	
class Decision(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	game = models.ForeignKey('GameState')
	balance = models.PositiveIntegerField()
	debt = models.PositiveIntegerField()
	
class Windmill(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	name = models.CharField(max_length=20)
	diameter = models.PositiveIntegerField(blank=False)
	capacity = models.PositiveIntegerField(blank=False)
	cost = models.PositiveIntegerField(blank=False)
	
	def __unicode__(self):
	  return str(self.name)
	
class Contract(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	noOfCitizens = models.IntegerField()
	usage = models.IntegerField()
	price = models.IntegerField()
	
class AcceptedContracts(Contract):
	user = models.ForeignKey(User)
	finalOffer = models.IntegerField()
	
class VolatileContracts(Contract):
	decision = models.ForeignKey('Decision')
	bid = models.IntegerField()	
	
class ReleasedContracts(Contract):
	game = models.ForeignKey('Game')
	
class Game(models.Model):
	id = UUIDField(primary_key=True, auto=True)
	turn = models.PositiveIntegerField()
	name = models.CharField(max_length=100)
	active_mills = models.ManyToManyField('Windmill', related_name='activeMills')
	storm = models.BooleanField(default=False)
	
	def __unicode__(self):
	  return str(self.name)